package com.salt.admin.api.feign.hystrix;

import com.salt.admin.api.feign.client.OfficeClient;
import com.salt.admin.api.model.Office;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Description 办公（后台管理中心）远程调用失败处理类
 * @Author salt
 * @Date 2020/8/18 16:44
 * @Version 1.0
 */
@Slf4j
@Component
public class OfficeClientHystrix implements FallbackFactory<OfficeClient> {
    @Override
    public OfficeClient create(Throwable throwable) {

        String message = throwable.getMessage() == null ?
                "No available server for client: ADMIN-CENTER" :
                throwable.getMessage();
        log.info("Hystrix:{}", message);

        return new OfficeClient() {

            @Override
            public Office get(String id) {
                log.info("--根据ID查询办公异常, id: " + id);
                return null;
            }

            @Override
            public Office getByOfficeName(String name) {
                log.info("--根据名称查询办公异常, name: " + name);
                return null;
            }

            @Override
            public List<Office> getChildren(String parentId) {
                log.info("--根据名称父节点ID查询办公异常, parentId: " + parentId);
                return null;
            }

            @Override
            public List<Office> getUserableChildren(String parentId) {
                return null;
            }

            @Override
            public List<Office> findList(Office office) {
                return null;
            }

            @Override
            public List<Office> findAllList(Office office) {
                log.info("--查询所有机构机构异常");
                return null;
            }

            @Override
            public List<String> treeDataIds(String id) {
                log.info("--根据名称父节点ID查询机构ID集合异常, parentId: " + id);
                return null;
            }

            @Override
            public List<Office> treeData(String id) {
                log.info("--根据名称父节点ID查询机构集合异常, parentId: " + id);
                return null;
            }

            @Override
            public List<Office> findByIds(List<String> ids) {
                log.info("--根据机构ID集合查询机构集合异常, ids: " + ids);
                return null;
            }
        };
    }
}
